<?php
class adm_dept_model extends CI_Model {

	public function __construct(){
		parent::__construct();
		$this->db = $this->load->database('default',true);
	}

	/**
	 * 查询区域列表
	 * @param string $parent_id
	 */
	public function  query_depts($parent_id) {
		$sql ="select * from adm_dept where dept_status ='1'and  parent_id ='$parent_id' order by dept_id asc";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->result_array();
		}
	}

	public function query_parent_id($dept_id){
		$sql ="select parent_id from adm_dept where dept_status ='1'and  dept_id ='$dept_id' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}

	public function query_dept_info($dept_id){
		$sql ="select * from  adm_dept where dept_status ='1'and  dept_id ='$dept_id' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}

	public function query_dept_info_by_name($dept_name){
		$sql ="select * from  adm_dept where dept_status ='1'and  dept_name ='$dept_name' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}
	public function insert_dept($dept){
		$dept['dept_status']=1;
		$this->db->insert('adm_dept',$dept);
	}
	public function update_dept($dept,$dept_id){
		$this->db->where('dept_id',$dept_id);
		$this->db->update('adm_dept',$dept);
	}

	public function set_delete_dept($dept_id){
		$sql ="update adm_dept set dept_status ='0' where dept_id='$dept_id'";
		$this->db->query($sql);
	}
}
?>